<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

final class CreateTableUser extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $table = $this->table('user', [
            'comment'   => '会员表',
            'engine'    => 'innodb',
        ]);
        $table->addColumn('account', 'string', [
            'comment'   => '账户',
            'null'      => false,
            'limit'     => 15
        ]);
        $table->addColumn('password', 'string', [
            'comment'   => '密码',
            'null'      => true,
            'default'   => '',
            'limit'     => 255
        ]);
        $table->addColumn('nickname', 'string', [
            'comment'   => '昵称',
            'null'      => true,
            'default'   => '',
            'limit'     => 32
        ]);
        $table->addColumn('salt', 'string', [
            'comment'   => '加密盐',
            'null'      => false,
            'limit'     => 8
        ]);
        $table->addColumn('is_lock', MysqlAdapter::PHINX_TYPE_TINY_INTEGER, [
            'comment'   => '锁定',
            'default'   => 0,
            'limit'     => 1
        ]);
        $table->addColumn('is_deleted', MysqlAdapter::PHINX_TYPE_TINY_INTEGER, [
            'comment'   => '删除',
            'default'   => 0,
            'null'      => false,
            'limit'     => 1
        ]);
        $table->addIndex('account', [
            'unique' => true,
            'name'   => 'uni_account'
        ]);
        $table->create();
    }
}
